package com.scm.erp.framework.utils;

import com.scm.erp.framework.handler.loginHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


import javax.annotation.Resource;

@Configuration
public class interceptorConfig extends WebMvcConfigurationSupport {
    @Resource
    private loginHandler loginhandler;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginhandler).addPathPatterns("/loginAction");
    }
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowCredentials(true).allowedHeaders("*").allowedOrigins("*").allowedMethods("*");
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**","**/**").addResourceLocations("classpath:/resources/","classpath:/static/","classpath:/templates/");
        super.addResourceHandlers(registry);
    }
}
